package com.gitee.dengmin.tenant.response;

public class ApiResult<T> {
    private int code = 200;
    private String message;
    private T data;

    public static String SUCCESS = "SUCCESS";

    public static ApiResult<?> error() {
        return error(500, "未知异常， 请联系管理员");
    }


    public static <T> ApiResult<T> error(String msg) {
        return error(500, msg);
    }

    public static <T> ApiResult<T> error(int code, String msg) {
        ApiResult<T> r = new ApiResult<>();
        r.setCode(code);
        r.setMessage(msg);
        return r;
    }

    public static <T> ApiResult<T> ok() {
        ApiResult<T> r = new ApiResult<>();
        r.setMessage(SUCCESS);
        return r;
    }

    public static <T> ApiResult<T> ok(String msg) {
        ApiResult<T> r = new ApiResult<>();
        r.setMessage(msg);
        return r;
    }

    public static <T> ApiResult<T> ok(T data) {
        ApiResult<T> r = new ApiResult<>();
        r.setMessage(SUCCESS);
        r.setData(data);
        return r;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
